/**
 * @author AIUHD74
 */

var sandwiches = [{
	"Name" : "Ham & Cheese",
	"Price" : "2.50",
	"Ingredients" : "ham,cheese,bread"

}, {
	"Name" : "Turkey & Cheese",
	"Price" : "2.75",
	"Ingredients" : "turkey,cheese,bread"
}, {
	"Name" : "Chicken Salad",
	"Price" : "3.75",
	"Ingredients" : "chicken salad,croissant"
}, {
	"Name" : "Roast Beef",
	"Price" : "4.50",
	"Ingredients" : "roast beef,bread"
}];

var inventory = [{
	"Name" : "ham",
	"Cost" : ".45",
	"Quality" : "0",
	"Type" : "pork",
	"Group" : "food"

}, {
	"Name" : "cheese",
	"Cost" : ".05",
	"Quality" : "0",
	"Type" : "dairy",
	"Group" : "food"
}, {
	"Name" : "turkey",
	"Cost" : ".40",
	"Quality" : "0",
	"Type" : "poultry",
	"Group" : "food"
}, {
	"Name" : "bread",
	"Cost" : ".02",
	"Quality" : "0",
	"Type" : "",
	"Group" : "food"
}, {
	"Name" : "croissant",
	"Cost" : ".04",
	"Quality" : "0",
	"Type" : "",
	"Group" : "food"
}, {
	"Name" : "chicken salad",
	"Cost" : ".50",
	"Quality" : "0",
	"Type" : "poultry",
	"Group" : "food"
}, {
	"Name" : "roast beef",
	"Cost" : ".60",
	"Quality" : "0",
	"Type" : "beef",
	"Group" : "food"
}];

var suppliers = [{
	"Name" : "Ben's Organic Market",
	"Description" : "An organic market. The products is more expensive but the quality is higher",
	"Quality" : "10",
	"Multiplier" : "1.5"

}, {
	"Name" : "Walmart",
	"Description" : "Average quality products for a reasonable price",
	"Quality" : "5",
	"Multiplier" : "1.1"

}, {
	"Name" : "Dumpster",
	"Description" : "Products from a dumpster.Low quality, low price. What did you expect?",
	"Quality" : "1",
	"Multiplier" : ".9"

}];


var inventoryQueue = new Array();
var supplier = "test";
var supplymultiplier = 1;
var menuQueue = new Array();
var selectedMenuQueue = new Array();


//add items to the menu queue
	objx(sandwiches).each(function(item) {
		menuQueue.push(item.Name);
	});
	//add ingredients to inventory queue
	objx(inventory).each(function(item) {
		inventoryQueue.push(item.Name);
	});
	
	
	
function getQuality()
{
	
	
}

function populateSuppliers() {

	objx(suppliers).each(function(item) {
		//loop through suppliers and add the to the select
		var x = document.getElementById("supselect");
		var option = document.createElement("option");
		option.text = item.Name;
		x.add(option);
		supplier = item.Name;
		supplymultiplier = parseFloat(item.Multiplier);
		document.getElementById("supselect").selectedIndex = document.getElementById("supselect").length - 1;
	});
}

function splitIngredients(string) {
	var str = string;
	return str.split(",");
}


function calcCost(list) {

	var iArray = splitIngredients(list);
	var cost = 0;
	for ( i = 0; i < iArray.length; i++) {
		objx(inventory).each(function(item) {

			if (item.Name == iArray[i]) {
				var iName = item.Name;
				var iCost = item.Cost;
				var iType = item.Type;
				var iGroup = item.Group;
				cost = ((cost + parseFloat(iCost)) * supplymultiplier);
				if (activeEventsQueue.length == 0) {

				} else {
					for ( x = 0; x < activeEventsQueue.length; x++) {

						var eventInfo = new Array();
						var effectArray = new Array();
						objx(events).each(function(item) {

							if (item.Name == activeEventsQueue[x]) {
								var eventName = item.Name;
								var eventDescription = item.Description;
								effectArray = item.Effect.split(",");

							}
						});

						if (effectArray[0] == iGroup) {
							if (effectArray[1] == iType) {
								var eventCost = parseFloat(effectArray[4]);
								cost = cost + eventCost;
								//notify("added " + eventCost +" to cost");
							}

						}
					}
				}

			}
		});
	}
	return cost;
}